package code.rocky.chapter03;

public class Suggest41 {

    interface Father {
        public int strong();
    }

    interface Mother {
        public int kind();
    }

    class FatherImpl implements Father {
        // 父亲的强壮指数是 8
        @Override
        public int strong() {
            return 8;
        }
    }

    class MotherImpl implements Mother {
        // 母亲的强壮指数是 8
        @Override
        public int kind() {
            return 8;
        }
    }
    private Son son = new Son();
    private Daughter daughter = new Daughter();

    class Son extends FatherImpl implements Mother {

        @Override
        public int strong() {
            return  super.strong() + 1;
        }

        @Override
        public int kind() {
            return new MotherSpecial().kind();
        }

        private class MotherSpecial extends MotherImpl {
            public int kind() {
                return super.kind() - 1;
            }
        }
    }

    class Daughter extends MotherImpl implements Father {

        @Override
        public int strong() {
            // 匿名内部类 来覆写父类的方法, 以完成继承父亲行为的功能
            return new FatherImpl() {
                public int strong() {
                    // 女儿强壮指数降低了
                    return super.strong() - 2;
                }
            }.strong();
        }
    }

    public static void main(String[] args) {
        Suggest41 suggest41 = new Suggest41();
        Son son = suggest41.son;
        System.out.println("son kind " +  son.kind());
        System.out.println("son strong " +  son.strong());

        Daughter daughter = suggest41.daughter;
        System.out.println("daughter kind " +  daughter.kind());
        System.out.println("daughter strong " +  daughter.strong());
    }
}


